using Microsoft.EntityFrameworkCore;
using Models;
using System.Text;

namespace WinApp_mysql_exist_db
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            InitDB();
            test();
        }

        static string _connectStr = "Server=localhost;Database=mcs_cosmax2022_v2;user=root;password=root;TreatTinyAsBoolean=true";

        public  DbContextOptionsBuilder<McsDbContext> _MCSDbOptionBuilder;

        private McsDbContext mcsDbContext;

        private void InitDB()
        {
            MySqlServerVersion serVersion = new MySqlServerVersion(new Version(8, 0, 29));

            _MCSDbOptionBuilder = new DbContextOptionsBuilder<McsDbContext>();
            
            _MCSDbOptionBuilder.UseMySql(_connectStr, serVersion, null);

            mcsDbContext = new McsDbContext(_MCSDbOptionBuilder.Options);
        }
            
        private void test()
        {
            List<MCS_Point> points = mcsDbContext.mcs_point.ToList();
            Console.WriteLine(points.Count);

            StringBuilder sb = new StringBuilder(); 

            foreach (MCS_Point point in points)
            {
                sb.Append($"point: {point.Id}, {point.UniqueNodeID} - {point.Status}\r\n");
            }

            MessageBox.Show(sb.ToString());
        }
    }
}